﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace NewSeasonFinder
{
    public partial class SeasonAdd : Form
    {
        XmlDocument xmlDoc;
        XmlNode xn_show;
        int lastSeason;

        public SeasonAdd(XmlDocument _xmlDoc, XmlNode _xn_show, int _lastSeason)
        {
            InitializeComponent();
            xmlDoc = _xmlDoc;
            xn_show = _xn_show;
            lastSeason = _lastSeason;
            numericUpDown1.Value = lastSeason + 1;
            numericUpDown1.Focus();
            numericUpDown1.Select(0, 20);
            this.Text += " / " + ShowXml.GetShowFullName(xn_show, ":");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int result = ShowXml.AddSeason(xmlDoc, xn_show, (int)numericUpDown1.Value);
            if (result == 0)
            {
                DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                string error = "未知错误";
                switch (result)
                {
                    case -3://剧集不存在
                        error = "要编辑的剧集已不存在";
                        break;
                    case -4://该季已存在
                        error = string.Format("第{0}季已经存在", (int)numericUpDown1.Value);
                        break;
                    default:
                        error = "未知错误";
                        break;
                }
                MessageBox.Show(error, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
